package com.ming.transaction.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.transaction.common.Result;
import com.ming.transaction.common.annotation.RecordLoggerAnnotation;
import com.ming.transaction.entity.Dialy;
import com.ming.transaction.service.IDialyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>
 * 日志管理 前端控制器
 * </p>
 *
 * @author 陈仕健
 * @since 2023-05-08
 */
@RestController
@RequestMapping("/dialy")
@Api(tags = "日志管理")
public class DialyController {

    @Value("${files.exp.path}")
    private String expPath;

    @Resource
    private IDialyService dialyService;

    /**
     * 管理员删除日志
     * @param id
     * @return
     */
    @ApiOperation("管理员删除日志")
    @DeleteMapping("/{id}")
    @RecordLoggerAnnotation(value = "管理员删除日志")
    public Result deleteLog(@PathVariable("id") Integer id) {
        return dialyService.deleteById(id);

    }

    /**
     * 管理员批量删除日志
     * @param ids
     * @return
     */
    @ApiOperation("管理员批量删除日志")
    @PostMapping("/del/batch")
    @RecordLoggerAnnotation(value = "管理员批量删除日志")
    public Result deleteLogs(@RequestBody List<Integer> ids) {
        return dialyService.deleteIds(ids);
    }

    /**
     * 日志分页查询
     * @param pageSize
     * @param pageNum
     * @param unumber
     * @param conmethod
     * @return
     */
    @ApiOperation("日志分页查询")
    @GetMapping("/page")
    public Result pageSearch(@RequestParam Integer pageSize,
                             @RequestParam Integer pageNum,
                             @RequestParam(defaultValue = "") String unumber,
                             @RequestParam(defaultValue = "") String conmethod) {
        return dialyService.pageSearch(pageNum,pageSize,unumber,conmethod);
    }

    /**
     * 日志导出 excel 表格
     * @param response
     * @throws Exception
     */
    @ApiOperation("管理员导出日志")
    @GetMapping("/exportExcel")
    public void export(HttpServletResponse response) throws Exception {
        dialyService.export(response);
    }



}

